using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IISHostingApplication;

namespace OOP33rdBatchApplication
{
    public class StudentGateway:DbGateway
    {
        public List<Student> GetAllStudentsOfDept(int departmentId)
        {
            List<Student> students = new List<Student>();
            string getStudentQuery = "SELECT * FROM t_Student WHERE dept_id =@departmentId";
            command.CommandText = getStudentQuery;
            command.Parameters.Add("@departmentId", SqlDbType.Int);
            command.Parameters["@departmentId"].Value = departmentId;
            connection.Open();
            using (SqlDataReader dataReader = command.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    Student student = new Student {Name = dataReader["Name"].ToString()};
                    student.Id = int.Parse(dataReader["Id"].ToString());
                    students.Add(student);
                }
            }
            connection.Close();
            return students;
        }
    }
}